﻿/*============================================
 * 类名 :TrueTable
 * 描述 :求真值表
 *   
 * 创建时间: 2009-11-2 23:41:12
 *============================================*/
using System;
using System.Collections.Generic;

using System.Text;

namespace 命题证明
{
    /// <summary>求真值表</summary>
    class TableWork
    {
        public TableWork( Expression exp )
        {
            this.expressTree = exp;
            CalTrueTable();
        }
        public TableWork( OperatorNode operatorNode )
            : this( new Expression( ExpressionFactory.ConvertToMiddle( operatorNode ) ) )
        {

        }

        Expression expressTree;

        List<OneRecord> records = new List<OneRecord>();
        /// <summary>记录的真值表</summary>
        public List<OneRecord> Records
        {
            get { return records; }
        }

        void CalTrueTable()
        {
            middles.Clear();
            records.Clear();
            if ( expressTree.Words.Count != 0 )
            {
                BinaryNumber b = new BinaryNumber( expressTree.Words.Count );
                for ( int i = 0; i <=b.Max ; i++ )
                {
                    b.DecimalNumber = i;
                    records.Add( new OneRecord( b.Clone(), expressTree.CalValue( b.Binary ) ) );
                    //middles.Add( expressTree. .ToList() );
                }
            }
        }

        List<List<MiddleParameter>> middles = new List<List<MiddleParameter>>();
        /// <summary>计算真值表时的中间过程</summary>
        public List<List<MiddleParameter>> Middles
        {
            get { return middles; }
            set { middles = value; }
        }
    }
}
